function [AllDataTraining, AllDataTesting, TrueLabelTraining, TrueLabelTesting, AllDataSampler] = Ddavid_sample_training_testing(AllData, TrueLabel, SampledDataSize)

% [AllDataTraining, AllDataTesting, TrueLabelTraining, TrueLabelTesting, AllDataSampler] = Ddavid_sample_training_testing(AllData, TrueLabel, SampledDataSize)
%
% <Input>
% AllData: [n*m], n is the size of dataset, m is the number of features
% TrueLabel: [n*k], n is the size of dataset, k is the number of labels
% SampledDataSize: Integer
%
% <Output>
% AllDataTraining: [SampledDataSize * m]
% AllDataTesting: [(n - SampledDataSize) * m]
% TrueLabelTraining: [SampledDataSize * m]
% TrueLabelTesting: [(n - SampledDataSize) * m]
% AllDataSampler: [1*n], the value is {0, 1} means the data is not sampled as training data or is sampled

AllDataSize = size(TrueLabel, 1);

AllDataSampler = [ones(1, SampledDataSize) zeros(1, AllDataSize - SampledDataSize)];

for Index = AllDataSize:-1:2
    NewIndex = randi(Index);
    Temp = AllDataSampler(NewIndex);
    AllDataSampler(NewIndex) = AllDataSampler(Index);
    AllDataSampler(Index) = Temp;
end

AllDataTraining = AllData(AllDataSampler == 1, :);
AllDataTesting = AllData(AllDataSampler == 0, :);
TrueLabelTraining = TrueLabel(AllDataSampler == 1, :);
TrueLabelTesting = TrueLabel(AllDataSampler == 0, :);
